﻿using S7.Net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 际海环境软件.Class
{
    class PLC
    {
        public static string ipaddr { get; private set; } = 际海环境软件.Properties.Settings.Default.PlcIP;
        public static string ipaddr1 { get; private set; } = 际海环境软件.Properties.Settings.Default.PlcIP1;

        static Plc S7200SMART = new Plc(CpuType.S71200, ipaddr, 0, 1);
        static Plc S7200SMART1 = new Plc(CpuType.S71200, ipaddr1, 0, 1);

        public static bool connectPLC(int num)
        {
            Plc plcName = null;
            if (num == 1) plcName = S7200SMART;
            if (num == 2) plcName = S7200SMART1;
            if (!plcName.IsConnected)
            {
                try
                {
                    plcName.Open();
                    return true;
                }
                catch (Exception ex)
                {
                    return false;
                }

            }
            else
            {
                return true;
            }
        }

    }
}
